package com.film.filmweb.controller;

import com.film.common.annotation.Log;
import com.film.common.core.controller.BaseController;
import com.film.common.core.domain.AjaxResult;
import com.film.common.core.page.TableDataInfo;
import com.film.common.enums.BusinessType;
import com.film.common.utils.poi.ExcelUtil;
import com.film.filmweb.domain.MovieUser;
import com.film.filmweb.service.IMovieUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 普通用户Controller
 *
 * @author ruoyi
 * @date 2025-09-05
 */
@RestController
@RequestMapping("/movie/user")
public class MovieUserController extends BaseController {
    @Autowired
    private IMovieUserService movieUserService;

    /**
     * 查询普通用户列表
     */
    @PreAuthorize("@ss.hasPermi('movie:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(MovieUser movieUser) {
        startPage();
        List<MovieUser> list = movieUserService.selectMovieUserList(movieUser);
        return getDataTable(list);
    }

    /**
     * 导出普通用户列表
     */
    @PreAuthorize("@ss.hasPermi('movie:user:export')")
    @Log(title = "普通用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MovieUser movieUser) {
        List<MovieUser> list = movieUserService.selectMovieUserList(movieUser);
        ExcelUtil<MovieUser> util = new ExcelUtil<MovieUser>(MovieUser.class);
        util.exportExcel(response, list, "普通用户数据");
    }

    /**
     * 获取普通用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('movie:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(movieUserService.selectMovieUserById(id));
    }

    /**
     * 新增普通用户
     */
    @PreAuthorize("@ss.hasPermi('movie:user:add')")
    @Log(title = "普通用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MovieUser movieUser) {
        return toAjax(movieUserService.insertMovieUser(movieUser));
    }

    /**
     * 修改普通用户
     */
    @PreAuthorize("@ss.hasPermi('movie:user:edit')")
    @Log(title = "普通用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MovieUser movieUser) {
        return toAjax(movieUserService.updateMovieUser(movieUser));
    }

    /**
     * 删除普通用户
     */
    @PreAuthorize("@ss.hasPermi('movie:user:remove')")
    @Log(title = "普通用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(movieUserService.deleteMovieUserByIds(ids));
    }

    @PutMapping("updatePassword")
    public AjaxResult updatePassword(@RequestBody MovieUser movieUser) {
        return toAjax(movieUserService.updatePassword(movieUser));
    }
}
